package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.system.domain.quality.QualityDefectType;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.mapper.QualityDefectTypeMapper;
import com.ruoyi.system.service.IQualityDefectTypeService;

import java.util.Optional;

/**
 * 质量缺陷类型Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@Service
public class QualityDefectTypeServiceImpl extends ServiceImpl<QualityDefectTypeMapper, QualityDefectType> implements IQualityDefectTypeService {



    @Override
    public boolean checkUnique(String table, String feild,String value,Long id) {
        Integer integer = this.baseMapper.checkUnique(table, feild, value);
        if((id==null&&integer!=null) || (integer!=null&&id!=null&&integer.intValue()!=id.intValue())){
            throw new CustomException(String.format("%s字段,值%s已存在!",feild,value));
        }
        return true;
    }

    @Override
    public boolean checkUnique(String table, String value,Long id) {
        Integer integer = this.baseMapper.checkUnique2(table, value);
        if((id==null&&integer!=null) || (integer!=null&&id!=null&&integer.intValue()!=id.intValue())){
            throw new CustomException(String.format("code值%s已存在!",value));
        }
        return true;
    }


}
